#include <windows.h>
#include "resource1.h"
#include "resource.h"
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <cstdio>          
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int Max = 7;
const int Maxnum = 199999999;
struct coord
{
	int x1,x2;
	int y1,y2;
}leg[Max][Max];
struct T
{
    int v, c;
}matrix[Max][Max];
struct E
{
    int u, v, flag;
}nod[Max];
int cpyv[10][6],num=0;
HWND ret,ret1,ret2;
	int dimcpy[10];
int lis[Max],flux;
char sir[100],sir2[10],sir3[50],sir4[10],cuv[2];
bool mark[Max];
int aflow, n=6, knum;
int pfs(int src, int tar);
int Maxflow(int src, int tar);
const char g_szClassName[] = "myWindowClass";
int a[7][7];
int sum=0;
int yes=0,da=0,des=0;
int vec[6],vdim=0,error1=0;
	HDC hdc;
	BOOL *ok;
	int id;
	int error=0,error3=0;
HFONT font;
LOGFONT LogFont;
POINT p[3];
int pfs(int src, int tar)
{
    queue<int> q1;
    int ans;
    memset(lis, 0, sizeof lis); 
    q1.push(src);
    while(!q1.empty()){
        ans = q1.front();
        q1.pop();
        for(int i = 1; i <= n; i++){
            if(matrix[ans][i].v < matrix[ans][i].c && lis[i] == 0){
                q1.push(i);
                lis[i] = ans;
                nod[i].u = ans;
                nod[i].v = i;
                nod[i].flag = 0;
                if(i == tar)return 1;
            }
            if(matrix[i][ans].v > 0 && lis[i] == 0){
                q1.push(i);
                lis[i] = ans;
                nod[i].u = i;
                nod[i].v = ans;
                nod[i].flag = 1;
                if(i == tar)return 1;
            }
        }
    }
    return 0;
}

BOOL CALLBACK diag3(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	
	switch(Message)
    {
        case WM_INITDIALOG:
			return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
			{
			case IDOK:
				yes=1;
				error=0;
				id =1003;
				a[1][1]=a[6][6]=0;
				for(int i=1;i<=5;i++)
				for(int j=2;j<=6;j++)
					if(i==j)
						a[i][j]=0;
					else
					{
						
						a[i][j]=GetDlgItemInt(hwnd,id,ok,FALSE);
						while(a[i][j]>9999999)
						a[i][j]=a[i][j]/10;
						id++;
					}
				for(int i=1;i<7;i++)
					for(int j=1;j<7;j++)
						matrix[i][j].c=a[i][j];
				
				for(int i=2;i<6;i++)
				{
					int slin=a[i][1]+a[i][6];
					int scol=a[1][i]+a[6][i];
					for(int j=2;j<6;j++)
					{
							slin+=a[i][j];
							scol+=a[j][i];
					}
					if(slin!=scol)
						error=1;
				}
				if(error==1)
				{
					for(int i=1;i<7;i++)
						for(int j=1;j<7;j++)
							{
								matrix[i][j].c=0;
								a[i][j]=0;
						}
				}
				EndDialog(hwnd, NULL);
				break;
			case IDC_EDIT6:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT10), FALSE );
				break;
			case IDC_EDIT10:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT6), FALSE );
				break;
			case IDC_EDIT7:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT14), FALSE );
				break;
			case IDC_EDIT14:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT7), FALSE );
				break;
			case IDC_EDIT8:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT18), FALSE );
				break;
			case IDC_EDIT18:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT8), FALSE );
				break;
			case IDC_EDIT11:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT15), FALSE );
				break;
			case IDC_EDIT15:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT11), FALSE );
				break;
			case IDC_EDIT12:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT19), FALSE );
				break;
			case IDC_EDIT19:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT12), FALSE );
				break;
			case IDC_EDIT16:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT20), FALSE );
				break;
			case IDC_EDIT20:
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT16), FALSE );
				break;
            case IDCANCEL:
               EndDialog(hwnd, NULL);
                break;
            }
        break;
		
        default:
            return FALSE;
    }
    return TRUE;
}
BOOL CALLBACK diag2(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDOK:
                    EndDialog(hwnd, NULL);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
}

BOOL CALLBACK diag1(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	int t;
	
	
	int src=1,tar=6;
    switch(Message)
    {
        case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
			case IDC_BUTTON1:
				 t = DialogBox(GetModuleHandle(NULL), 
					 MAKEINTRESOURCE(IDD_DIALOG2), hwnd,diag3);
            if(t == IDOK)
			{
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(t == IDCANCEL)
			{
                MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(t == -1)
			{
                MessageBox(hwnd, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
            }
			error1=error;
			if(error==0)
			{
					EndDialog(hwnd,IDCANCEL);
					EnableWindow(ret1,TRUE);
			}
			else
			{
				
				ShowWindow(hwnd,SW_MAXIMIZE);
				ShowWindow(hwnd,SW_NORMAL);
			}
			
				break;
			case IDC_BUTTON2:
				{
					if(error1==1)
						break;
					
					des=0;
					aflow = Maxnum;  
					if(!pfs(src, tar))
					{
							EndDialog(hwnd, IDCANCEL);
							da=1;
							break;
					}
					des=1;
					int tmp = tar;
					vdim=0;
					while(tmp != 1)
					{
					int u = nod[tmp].u, v = nod[tmp].v;
					vec[vdim]=u;
					vdim++;
					if(nod[tmp].flag == 0)
						aflow = min(matrix[u][v].c - matrix[u][v].v, aflow);
						else aflow = min(matrix[u][v].v, aflow);
						tmp = lis[tmp];
					}
					tmp = tar;
					while(tmp != 1)
					{
					int u = nod[tmp].u, v = nod[tmp].v;
					if(nod[tmp].flag == 0)
						matrix[u][v].v += aflow;
						else matrix[u][v].v -= aflow;
						tmp = lis[tmp];
					}
					flux=aflow;
					if(aflow != Maxnum)
					sum += aflow;
					ShowWindow(hwnd,SW_MAXIMIZE);
					ShowWindow(hwnd,SW_NORMAL);
					break;
				}
			case IDC_BUTTON3:
				
				sum=0;
				da=0;
				yes=0;
				des=0;
				for(int i=0;i<10;i++)
					for(int j=0;j<6;j++)
						cpyv[i][j]=0;
				for(int i=1;i<7;i++)
						for(int j=1;j<7;j++)
						{
								matrix[i][j].c=0;
								matrix[i][j].v=0;
									a[i][j]=0;
						}
				error=0;
				error1=0;
				num=0;
				for(int i=0;i<10;i++)
				dimcpy[i]=0;
				vdim=0;
				for(int i=0;i<6;i++)
					vec[i]=0;
				ShowWindow(ret1,9);
				ShowWindow(ret,9);
				EnableWindow(ret1,FALSE);
				
				break;

            case IDOK:
                    EndDialog(hwnd, IDCANCEL);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
}
 



// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

	//RECT *prc;
	
	
	int t;
	HPEN	   hPen;
	PAINTSTRUCT Ps;
	HFONT hf;
	HDC hdc;
	COLORREF clrPurple  = RGB(70, 25, 255);
	COLORREF clrRed  = RGB(255, 25, 5);
	COLORREF clrPinkie=RGB(255,120,100);
	COLORREF clrBlue = RGB(12, 25, 255);
	COLORREF clrBlack=RGB(0,0,0);
	COLORREF clrWhite=RGB(255,255,255);
	char szTitle[] = "Algortimul Edmonds-Karp:    DEMONSTRATOR GRAFIC";
	char s[10],f[10];
	HBRUSH  NewBrush;
    switch(msg)
    {
		case WM_CREATE :
		ret=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_FORMVIEW),hwnd,diag1);
		if(ret)
					ShowWindow(ret,SW_SHOW),
				     EndDialog(hwnd, IDOK);
		ret1=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_FORMVIEW1),hwnd,diag1);
		ret2=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_FORMVIEW2),hwnd,diag1);
		if(ret1)
					ShowWindow(ret1,SW_SHOW),
				     EndDialog(hwnd, IDOK);  
				break;
		if(ret)
			ShowWindow(ret1,SW_SHOW),
		     EndDialog(hwnd, IDOK);
		break;
        
		case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
		case WM_COMMAND :
			switch(LOWORD(wParam))
			{
			case ID_FILE_HELP :
				 t = DialogBox(GetModuleHandle(NULL), 
					 MAKEINTRESOURCE(IDD_DIALOG1), hwnd,diag2);
            if(t == IDOK)
			{
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(t == IDCANCEL)
			{
                MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(t == -1)
			{
                MessageBox(hwnd, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
            }
			break;
			}
        break;
		case WM_PAINT:

			hdc =BeginPaint(hwnd,&Ps);
			SetTextColor(hdc, clrPurple);
			SetBkColor(hdc, clrPinkie);
			TextOut(hdc,110,5,szTitle,strlen(szTitle)+1);
			RoundRect(hdc,50,90,90,130,10,10);
			SetTextColor(hdc, clrBlue);
			SetBkColor(hdc, clrWhite);
			TextOut(hdc,65,100,"S",1);
			RoundRect(hdc,130,30,170,70,10,10);
			SetTextColor(hdc, clrBlack);
			TextOut(hdc,145,40,"a",1);
			RoundRect(hdc,130,150,170,190,10,10);
			TextOut(hdc,145,160,"c",1);
			RoundRect(hdc,210,30,250,70,10,10);
			TextOut(hdc,225,40,"b",1);
			RoundRect(hdc,210,150,250,190,10,10);
			TextOut(hdc,225,160,"e",1);
			RoundRect(hdc,290,90,330,130,10,10);
			SetTextColor(hdc, clrBlue);
			TextOut(hdc,305,100,"D",1);
			
			
			LogFont.lfStrikeOut = 0;
			LogFont.lfUnderline = 0;
			LogFont.lfHeight = 14;
			LogFont.lfEscapement = 0;
			LogFont.lfItalic = FALSE;
			if(error==1)
			{

				hdc = GetDC(hwnd);

				TextOut(hdc,100,300,"Graf incorect!Mai incercati!",35);
				ReleaseDC(hwnd, hdc);
			}
			else
			{
				hdc = GetDC(hwnd);

				TextOut(hdc,100,300,"                                                                         ",50);
				ReleaseDC(hwnd, hdc);
			}
			if (yes==1)
			{
				 hdc = GetDC(hwnd);
				 font = CreateFontIndirect(&LogFont);
				 SelectObject(hdc, font);
				 NewBrush = CreateSolidBrush(clrBlack);
				 SelectObject(hdc, NewBrush);
				if(a[1][2]!=0)
				{
					leg[1][2].x1=90;
					leg[1][2].x2=130;
					leg[1][2].y1=110;
					leg[1][2].y2=50;
					strcpy(f,"0/");
					itoa(a[1][2],s,10);
					strcat(f,s);
					TextOut(hdc,90,60,f,strlen(f));
					p[0].x=130;
					p[0].y=50;
					p[1].x=122;
					p[1].y=57;
					p[2].x=128;
					p[2].y=62;
					Polygon(hdc,p,3);
					MoveToEx(hdc,90,110,NULL);
					LineTo(hdc,130,50);
				}
				if(a[1][3]!=0)
				{
					leg[1][3].x1=90;
					leg[1][3].x2=210;
					leg[1][3].y1=110;
					leg[1][3].y2=50;
					strcpy(f,"0/");
					itoa(a[1][3],s,10);
					strcat(f,s);
					p[0].x=210;
					p[0].y=50;
					p[1].x=198;
					p[1].y=51;
					p[2].x=205;
					p[2].y=60;
					Polygon(hdc,p,3);
					TextOut(hdc,150,80,f,strlen(f));
					MoveToEx(hdc,90,110,NULL);
					LineTo(hdc,210,50);
				}
				if(a[1][4]!=0)
				{
					leg[1][4].x1=90;
					leg[1][4].x2=130;
					leg[1][4].y1=110;
					leg[1][4].y2=170;
					strcpy(f,"0/");
					itoa(a[1][4],s,10);
					strcat(f,s);
					TextOut(hdc,85,135,f,strlen(f));
					p[0].x=130;
					p[0].y=170;
					p[1].x=130;
					p[1].y=160;
					p[2].x=120;
					p[2].y=165;
					Polygon(hdc,p,3);
					MoveToEx(hdc,90,110,NULL);
					LineTo(hdc,130,170);
				}
				if(a[1][5]!=0)
				{
					leg[1][5].x1=90;
					leg[1][5].x2=210;
					leg[1][5].y1=110;
					leg[1][5].y2=170;
					strcpy(f,"0/");
					itoa(a[1][5],s,10);
					strcat(f,s);
					TextOut(hdc,150,130,f,strlen(f));
					p[0].x=210;
					p[0].y=170;
					p[1].x=200;
					p[1].y=160;
					p[2].x=195;
					p[2].y=172;
					Polygon(hdc,p,3);
					MoveToEx(hdc,90,110,NULL);
					LineTo(hdc,210,170);
				}
				if(a[1][6]!=0)
				{
					leg[1][6].x1=90;
					leg[1][6].x2=290;
					leg[1][6].y1=110;
					leg[1][6].y2=110;
					strcpy(f,"0/");
					itoa(a[1][6],s,10);
					strcat(f,s);
					TextOut(hdc,190,95,f,strlen(f));
					p[0].x=290;
					p[0].y=110;
					p[1].x=280;
					p[1].y=105;
					p[2].x=280;
					p[2].y=115;
					Polygon(hdc,p,3);
					MoveToEx(hdc,90,110,NULL);
					LineTo(hdc,290,110);
				}
				if(a[2][3]!=0 || a[3][2]!=0)
				{
					leg[2][3].x1=leg[3][2].x1=170;
					leg[2][3].x2=leg[3][2].x2=210;
					leg[2][3].y1=leg[3][2].y1=50;
					leg[2][3].y2=leg[3][2].y2=50;
					if(a[2][3]==0)
					{
						strcpy(f,"0/");
						itoa(a[3][2],s,10);
						strcat(f,s);
						TextOut(hdc,180,35,f,strlen(f));
						p[0].x=170;
						p[0].y=50;
						p[1].x=180;
						p[1].y=55;
						p[2].x=180;
						p[2].y=45;
						Polygon(hdc,p,3);
					}
					else
					{
						strcpy(f,"0/");
						itoa(a[2][3],s,10);
						strcat(f,s);
						TextOut(hdc,180,35,f,strlen(f));
						p[0].x=210;
						p[0].y=50;
						p[1].x=200;
						p[1].y=55;
						p[2].x=200;
						p[2].y=45;
						Polygon(hdc,p,3);
					}
					MoveToEx(hdc,170,50,NULL);
					LineTo(hdc,210,50);
				}
				if(a[2][4]!=0 || a[4][2]!=0)
				{
					leg[2][4].x1=leg[4][2].x1=150;
					leg[2][4].x2=leg[4][2].x2=150;
					leg[2][4].y1=leg[4][2].y1=70;
					leg[2][4].y2=leg[4][2].y2=150;
					if(a[2][4]==0)
					{

						strcpy(f,"0/");
						itoa(a[4][2],s,10);
						strcat(f,s);
						TextOut(hdc,130,100,f,strlen(f));
						p[0].x=150;
						p[0].y=70;
						p[1].x=155;
						p[1].y=80;
						p[2].x=145;
						p[2].y=80;
						Polygon(hdc,p,3);
					}
					else
					{
						strcpy(f,"0/");
						itoa(a[2][4],s,10);
						strcat(f,s);
						TextOut(hdc,130,100,f,strlen(f));
						p[0].x=150;
						p[0].y=150;
						p[1].x=155;
						p[1].y=140;
						p[2].x=145;
						p[2].y=140;
						Polygon(hdc,p,3);
					}
					MoveToEx(hdc,150,70,NULL);
					LineTo(hdc,150,150);
				}
				if(a[2][5]!=0 || a[5][2]!=0)
				{
					leg[2][5].x1=leg[5][2].x1=150;
					leg[2][5].x2=leg[5][2].x2=230;
					leg[2][5].y1=leg[5][2].y1=70;
					leg[2][5].y2=leg[5][2].y2=150;
					if(a[2][5]==0)
					{
						strcpy(f,"0/");
						itoa(a[5][2],s,10);
						strcat(f,s);
						TextOut(hdc,207,112,f,strlen(f));
						p[0].x=150;
						p[0].y=70;
						p[1].x=152;
						p[1].y=80;
						p[2].x=160;
						p[2].y=75;
						Polygon(hdc,p,3);
					}
					else
					{
						strcpy(f,"0/");
						itoa(a[2][5],s,10);
						strcat(f,s);
						TextOut(hdc,207,112,f,strlen(f));
						p[0].x=230;
						p[0].y=150;
						p[1].x=220;
						p[1].y=145;
						p[2].x=225;
						p[2].y=140;
						Polygon(hdc,p,3);
					}
					MoveToEx(hdc,150,70,NULL);
					LineTo(hdc,230,150);
				}
				if(a[2][6]!=0)
				{
					leg[2][6].x1=150;
					leg[2][6].x2=290;
					leg[2][6].y1=70;
					leg[2][6].y2=110;
					strcpy(f,"0/");
					itoa(a[2][6],s,10);
					strcat(f,s);
					TextOut(hdc,210,75,f,strlen(f));
					p[0].x=290;
					p[0].y=110;
					p[1].x=280;
					p[1].y=112;
					p[2].x=285;
					p[2].y=102;
					Polygon(hdc,p,3);
					MoveToEx(hdc,150,70,NULL);
					LineTo(hdc,290,110);//D
				}
				if(a[3][4]!=0 || a[4][3]!=0)
				{
					leg[4][3].x1=leg[3][4].x1=230;
					leg[4][3].x2=leg[3][4].x2=150;
					leg[4][3].y1=leg[3][4].y1=70;
					leg[4][3].y2=leg[3][4].y2=150;
					if(a[3][4]==0)
					{
						strcpy(f,"0/");
						itoa(a[4][3],s,10);
						strcat(f,s);
						TextOut(hdc,190,110,f,strlen(f));
						p[0].x=230;
						p[0].y=70;
						p[1].x=220;
						p[1].y=75;
						p[2].x=232;
						p[2].y=77;
						Polygon(hdc,p,3);
					}
					else
					{
						strcpy(f,"0/");
						itoa(a[3][4],s,10);
						strcat(f,s);
						TextOut(hdc,190,110,f,strlen(f));
						p[0].x=150;
						p[0].y=150;
						p[1].x=150;
						p[1].y=140;
						p[2].x=160;
						p[2].y=145;
						Polygon(hdc,p,3);
					}
					MoveToEx(hdc,230,70,NULL);
					LineTo(hdc,150,150);
				}
				if(a[3][5]!=0 || a[5][3]!=0)
				{
					leg[5][3].x1=leg[3][5].x1=230;
					leg[5][3].x2=leg[3][5].x2=230;
					leg[5][3].y1=leg[3][5].y1=70;
					leg[5][3].y2=leg[3][5].y2=150;
					if(a[3][5]==0)
					{
						strcpy(f,"0/");
						itoa(a[5][3],s,10);
						strcat(f,s);
						TextOut(hdc,235,110,f,strlen(f));
						p[0].x=230;
						p[0].y=70;
						p[1].x=235;
						p[1].y=80;
						p[2].x=225;
						p[2].y=80;
						Polygon(hdc,p,3);
					}
					else
					{
						strcpy(f,"0/");
						itoa(a[3][5],s,10);
						strcat(f,s);
						TextOut(hdc,235,110,f,strlen(f));
						p[0].x=230;
						p[0].y=150;
						p[1].x=235;
						p[1].y=140;
						p[2].x=225;
						p[2].y=140;
						Polygon(hdc,p,3);
					}
					MoveToEx(hdc,230,70,NULL);
					LineTo(hdc,230,150);
				}
				if(a[3][6]!=0)
				{
					leg[3][6].x1=250;
					leg[3][6].x2=290;
					leg[3][6].y1=50;
					leg[3][6].y2=110;
					strcpy(f,"0/");
					itoa(a[3][6],s,10);
					strcat(f,s);
					TextOut(hdc,275,70,f,strlen(f));
					p[0].x=290;
					p[0].y=110;
					p[1].x=278;
					p[1].y=100;
					p[2].x=288;
					p[2].y=95;
					Polygon(hdc,p,3);
					MoveToEx(hdc,250,50,NULL);
					LineTo(hdc,290,110);
				}
				if(a[4][5]!=0 || a[5][4]!=0)
				{
					leg[4][5].x1=leg[5][4].x1=170;
					leg[4][5].x2=leg[5][4].x2=210;
					leg[4][5].y1=leg[5][4].y1=170;
					leg[4][5].y2=leg[5][4].y2=170;
					if(a[4][5]==0)
					{
						strcpy(f,"0/");
						itoa(a[5][4],s,10);
						strcat(f,s);
						TextOut(hdc,180,172,f,strlen(f));
						p[0].x=170;
						p[0].y=170;
						p[1].x=180;
						p[1].y=175;
						p[2].x=180;
						p[2].y=165;
						Polygon(hdc,p,3);
					}
					else
					{
						strcpy(f,"0/");
						itoa(a[4][5],s,10);
						strcat(f,s);
						TextOut(hdc,180,172,f,strlen(f));
						p[0].x=210;
						p[0].y=170;
						p[1].x=200;
						p[1].y=175;
						p[2].x=200;
						p[2].y=165;
						Polygon(hdc,p,3);
					}
					MoveToEx(hdc,170,170,NULL);
					LineTo(hdc,210,170);
				}
				if(a[4][6]!=0)
				{
					leg[4][6].x1=150;
					leg[4][6].x2=290;
					leg[4][6].y1=150;
					leg[4][6].y2=110;
					strcpy(f,"0/");
					itoa(a[4][6],s,10);
					strcat(f,s);
					TextOut(hdc,220,130,f,strlen(f));
					p[0].x=290;
					p[0].y=110;
					p[1].x=280;
					p[1].y=110;
					p[2].x=285;
					p[2].y=115;
					Polygon(hdc,p,3);
					MoveToEx(hdc,150,150,NULL);
					LineTo(hdc,290,110);
				}
				if(a[5][6]!=0)
				{
					leg[5][6].x1=250;
					leg[5][6].x2=290;
					leg[5][6].y1=170;
					leg[5][6].y2=110;
					strcpy(f,"0/");
					itoa(a[5][6],s,10);
					strcat(f,s);
					TextOut(hdc,270,140,f,strlen(f));
					p[0].x=290;
					p[0].y=110;
					p[1].x=280;
					p[1].y=115;
					p[2].x=288;
					p[2].y=120;
					Polygon(hdc,p,3);
					MoveToEx(hdc,250,170,NULL);
					LineTo(hdc,290,110);
				}
				DeleteObject(NewBrush);
				ReleaseDC(hwnd, hdc);
				DeleteObject(font);
			}
			
			if(des==1)
			{
				strcpy(sir,"Fluxul ce este adaugat este: ");
				itoa(flux,sir2,10);
				strcat(sir,sir2);
				
				hdc= GetDC(hwnd);
				hPen = CreatePen(PS_SOLID, 1, clrBlue);
				SelectObject(hdc, hPen);
				for(int j=0;j<num;j++)
				{
				MoveToEx(hdc,leg[cpyv[j][0]][6].x1,leg[cpyv[j][0]][6].y1,NULL);
				LineTo(hdc,leg[cpyv[j][0]][6].x2,leg[cpyv[j][0]][6].y2);
				for(int i=dimcpy[j];i>0;i--)
				{
					MoveToEx(hdc,leg[cpyv[j][i]][cpyv[j][i-1]].x1,leg[cpyv[j][i]][cpyv[j][i-1]].y1,NULL);
					LineTo(hdc,leg[cpyv[j][i]][cpyv[j][i-1]].x2,leg[cpyv[j][i]][cpyv[j][i-1]].y2);
				}
				}
				
				TextOut(hdc,100,300,sir,strlen(sir));
				
				hPen = CreatePen(PS_SOLID, 1, clrRed);
				SelectObject(hdc, hPen);
				MoveToEx(hdc,leg[vec[0]][6].x1,leg[vec[0]][6].y1,NULL);
				LineTo(hdc,leg[vec[0]][6].x2,leg[vec[0]][6].y2);
				for(int i=vdim;i>0;i--)
				{
					MoveToEx(hdc,leg[vec[i]][vec[i-1]].x1,leg[vec[i]][vec[i-1]].y1,NULL);
					LineTo(hdc,leg[vec[i]][vec[i-1]].x2,leg[vec[i]][vec[i-1]].y2);
				}
				for(int i=0;i<vdim;i++)
					cpyv[num][i]=vec[i];
				dimcpy[num]=vdim;
				num++;
				//SetTextColor(hdc, clrBlack);
				
				ReleaseDC(hwnd, hdc);
			}
			
			if(da==1)
			{
				strcpy(sir3,"Fluxul maxim este: ");
				itoa(sum,sir4,10);
				strcat(sir3,sir4);
				hdc= GetDC(hwnd);
				TextOut(hdc,100,300,"                                                                              ",60);
				TextOut(hdc,100,300,sir3,strlen(sir3));
				ReleaseDC(hwnd, hdc);
			}
			EndPaint(hwnd,&Ps);
			break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;

}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Algoritm Edmonds-Karp: Demonstrator grafic",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 600, 500,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
//
}